package com.im.app.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.im.app.model.Admin;
import com.im.app.model.FlowRecordLogs;
import com.im.app.service.IFlowRecordLogsService;
import com.im.app.utils.Response;
import com.im.app.utils.ResponseResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;

/**
 * 流水信息Controller
 *
 * @author ruoyi
 * @date 2023-06-12
 */
@Controller
@RequestMapping("/flowRecordLogs")
public class FlowRecordLogsController extends BaseController
{

    @Resource
    private IFlowRecordLogsService flowRecordLogsService;

    @GetMapping(value = "/getFlowRecordLogs")
    public ResponseResult<Page<FlowRecordLogs>> getFlowRecordLogs(@RequestHeader String token, FlowRecordLogs flowRecordLogs, int currPage, int pageSize){
        Admin admin = getAdmin(token);
        if (admin == null){
            return Response.makeRsp(401,"登录已过期");
        }
        flowRecordLogs.setAdminId(admin.getId());
        Page<FlowRecordLogs> list = flowRecordLogsService.selectFlowRecordLogsList(flowRecordLogs,currPage,pageSize);
        return Response.makeOKRsp(list);
    }

    @PostMapping(value = "/add")
    public ResponseResult<Object> addFlowRecordLogs(@RequestHeader String token,FlowRecordLogs flowRecordLogs){
        Admin admin = getAdmin(token);
        if (admin == null){
            return Response.makeRsp(401,"登录已过期");
        }
        flowRecordLogs.setAdminId(admin.getId());
        int i = flowRecordLogsService.insertFlowRecordLogs(flowRecordLogs);
        if (i > 0){
            return Response.makeOKRsp("添加成功");
        }else {
            return Response.makeErrRsp("添加失败");
        }
    }


}
